<template>
    <div>
        <!-- 该文件是饼状图模板 -->
        <div id="pie_wrap" style="width:100%;height:350px"></div>
    </div>
</template>

<script>
export default {
    props: {
        title: {},
        pieData: {
            type: Array
        }
    },
    mounted() {
        // console.log(111)
        this.initBar()
    },
    watch: {
        pieData() {
            this.initBar()
        }
    },
    methods: {
        initBar() {
            console.log(this.$echarts)
            // 基于准备好的dom，初始化echarts实例
            var myChart = this.$echarts.init(document.getElementById('pie_wrap'));
            //设置配置项
            var option = {
                title: {
                    text: this.title,
                    left: 'center',
                    textStyle: {
                        color: '#fff'
                    }
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: '人数',
                        type: 'pie',
                        radius: '50%',
                        data:this.pieData,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            }
            // 绘制图表
            myChart.setOption(option);
        }
    }
}
</script>

<style lang="less" scoped></style>